package com.example.web.controller;

import com.example.api.service.DeepseekService;
import com.example.common.model.ChatRequest;
import com.example.common.model.ChatResponse;
import io.github.pigmesh.ai.deepseek.core.DeepSeekClient;
import io.github.pigmesh.ai.deepseek.core.chat.ChatCompletionResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Flux;

@RestController
@RequestMapping("/api/chat")
public class ChatController {

    @Autowired
    private DeepseekService deepseekService;

    @Autowired
    private DeepSeekClient deepSeekClient;

    @PostMapping
    public ChatResponse chat(@RequestBody ChatRequest request) {
        return deepseekService.chat(request);
    }

    @GetMapping(value = "/chat", produces = MediaType.TEXT_EVENT_STREAM_VALUE + ";charset=UTF-8")
    public Flux<ChatCompletionResponse> chat(String prompt) {
        return deepSeekClient.chatFluxCompletion(prompt);
    }

    /**
     * 用于测试服务是否发布成功的方法
     * @return 返回一个简单的成功消息
     */
    @GetMapping("/health")
    public String healthCheck() {
        return "Service is up and running!";
    }
}
